/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package forum.communication;

import forum.server.controller.ForumFacadeInt;
import forum.server.exceptions.DatabaseException;
import forum.server.exceptions.NoSuchPostException;
import forum.server.exceptions.NotLoggedInException;
import forum.server.exceptions.UnauthorizedOpException;

/**
 *
 * @author furmanal
 */
public class DeleteMessageMessage extends ClientMessage {

	private static final long serialVersionUID = -5664329636261548253L;
	private int postID;

    public DeleteMessageMessage(int id){
        this.postID = id;
    }

    @Override
    public ServerResponse doOperation(ForumFacadeInt forum) {
        try {
            forum.deletePost(postID);
            return new ServerResponse("The post #"+this.postID+" was successfully deleted", true);
		} catch (UnauthorizedOpException e) {
			return new ServerResponse(e.getMessage(), false);
		} catch (NotLoggedInException e) {
			return new ServerResponse("Guests cannot delete posts. Please login.", false);
		} catch (NoSuchPostException e) {
			return new ServerResponse(e.getMessage(), false);
		} catch (DatabaseException e) {
			return new ServerResponse("The server is currently down for maintanance.\nPlease try again later.",false);
		}

    }

}
